﻿using Colorful.Furniture.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Colorful.Furniture.PermissionManagement
{
    /// <summary>
    ///  设置角色权限输入
    /// </summary>
    public class SetRolePermissionInputDto
    {
        /// <summary>
        ///  角色编码
        /// </summary>
        public Guid RoleId { get; set; }

        /// <summary>
        ///  权限编码
        /// </summary>
        [Required(ErrorMessage = "请设置权限")]
        public List<Guid?> PermissionIdList { get; set; }
    }

    /// <summary>
    ///  设置角色数据权限输入
    /// </summary>
    public class SetRoleDataPermissionInputDto
    {
        /// <summary>
        ///  角色编码
        /// </summary>
        public Guid RoleId { get; set; }

        /// <summary>
        ///  权限类型集合
        /// </summary>
        public List<string> PermissionTypeList { get; set; }

        /// <summary>
        ///  数据权限类型，多个以逗号分隔
        /// </summary>
        public string PermissionType => PermissionTypeList.ListToString();

        /// <summary>
        ///  跨级部门集合
        /// </summary>
        public List<string> CrossLevelDepartList { get; set; }

        /// <summary>
        ///  跨级部门，多个以逗号分隔
        /// </summary>
        public string CrossLevelDepart => CrossLevelDepartList.ListToString();
    }

    /// <summary>
    ///  角色列表请求体
    /// </summary>
    public class RoleListInputDto
    {
        /// <summary>
        /// 关键词
        /// </summary>
        public string Keywords { get; set; }
    }

    /// <summary>
    ///  角色列表输出体
    /// </summary>
    public class RoleOutputDto
    {

        /// <summary>
        /// 编码
        /// </summary>

        public Guid Id { get; set; }

        /// <summary>
        /// 角色代码
        /// </summary>

        public string Code { get; set; }

        /// <summary>
        /// 是否禁用
        /// </summary>

        public bool IsDisabled { get; set; }

        /// <summary>
        /// 是否系统默认
        /// </summary>

        public bool IsSystem { get; set; }

        /// <summary>
        ///  机构编码
        /// </summary>
        public Guid? OrganizationId { get; set; }

        /// <summary>
        ///  机构名字
        /// </summary>
        public string OrganizationName { get; set; }

        /// <summary>
        /// 角色名字
        /// </summary>

        public string Name { get; set; }

        /// <summary>
        /// 角色描述
        /// </summary>

        public string Remark { get; set; }

    }

    /// <summary>
    ///  权限带资源
    /// </summary>
    public class PermissionWithResourceOutputDto
    {
        /// <summary>
        ///  资源名字
        /// </summary>
        public string ResourceName { get; set; }

        /// <summary>
        ///  资源图标
        /// </summary>
        public string ResourceIcon { get; set; }

        /// <summary>
        ///  排序
        /// </summary>
        public int Sort { get; set; }

        /// <summary>
        ///  资源编码
        /// </summary>
        public Guid ResourceId { get; set; }

        /// <summary>
        ///  资源标题
        /// </summary>
        public string ResourceTitle { get; set; }

        /// <summary>
        ///  资源父级编码
        /// </summary>
        public Guid? ResourceParentId { get; set; }
    }

    /// <summary>
    ///  角色数据权限
    /// </summary>
    public class RoleDataPermissionOutputDto
    {
        /// <summary>
        ///  权限类型
        /// </summary>
        public List<string> PermissionTypeList => PermissionType.StringToList<string>()??new List<string>();

        /// <summary>
        ///  权限类型
        /// </summary>
        [JsonIgnore]
        public string PermissionType { get; set; }

        /// <summary>
        ///  跨级部门集合
        /// </summary>
        public List<string> CrossLevelDepartList => CrossLevelDepart.StringToList<string>()??new List<string>();

        /// <summary>
        ///  跨级部门
        /// </summary>
        [JsonIgnore]
        public string CrossLevelDepart { get; set; }

        /// <summary>
        ///  角色编码
        /// </summary>
        public Guid? RoleId { get; set; }
    }

    /// <summary>
    ///  角色权限的资源输出体
    /// </summary>
    public class RolePermissionResourceOutputDto : PermissionWithResourceOutputDto
    {
        /// <summary>
        ///  权限编码
        /// </summary>
        public Guid? PermissionId { get; set; }

        /// <summary>
        ///  操作排序
        /// </summary>
        public int OperationSort { get; set; }

        /// <summary>
        ///  操作标题
        /// </summary>
        public string OperationTitle { get; set; }

        /// <summary>
        ///  操作名字
        /// </summary>
        public string OperationName { get; set; }
    }

    /// <summary>
    ///  资源权限列表
    /// </summary>
    public class ResourceWithPermissionOutputDto : PermissionWithResourceOutputDto
    {
        /// <summary>
        ///  权限列表
        /// </summary>
        public List<Permission1OutputDto> PermissionList { get; set; }
    }

    /// <summary>
    ///   权限列表输出体
    /// </summary>
    public class Permission1OutputDto
    {
        /// <summary>
        ///  权限编码
        /// </summary>
        public Guid? PermissionId { get; set; }

        /// <summary>
        ///  操作标题
        /// </summary>
        public string OperationTitle { get; set; }

        /// <summary>
        ///  操作名字
        /// </summary>
        public string OperationName { get; set; }
    }

    /// <summary>
    ///  角色保存请求体
    /// </summary>
    public class RoleSaveInputDto
    {
        /// <summary>
        /// 编码
        /// </summary>

        public Guid? Id { get; set; }

        /// <summary>
        /// 角色代码
        /// </summary>

        public string Code { get; set; }

        /// <summary>
        /// 是否禁用
        /// </summary>

        public bool IsDisabled { get; set; }

        /// <summary>
        /// 角色名字
        /// </summary>

        public string Name { get; set; }

        /// <summary>
        /// 角色描述
        /// </summary>

        public string Remark { get; set; }

    }
}